import 'package:flutter/material.dart';
import 'package:flutter_widgets/flutter_widgets.dart';

import 'models/assets.dart';

/// 自定控件所需样式优先从ThemeData获取，如果原生不支持或者有冲突的，则定义在自定义样式里。
///
/// {@tool src.sample}
/// ```
/// return WidgetTheme(
///      data: WidgetThemeData(),
///      child: MaterialApp(
///        theme: ThemeData(),
///        home: MyHome(),
///      ),
///    );
/// ```
/// {@end-tool}
/// 更多参考sample [WidgetsSample]
class WidgetTheme extends InheritedWidget {
  final WidgetThemeData data;

  const WidgetTheme({
    super.key,
    required this.data,
    required super.child,
  });

  static WidgetThemeData? of(BuildContext context) {
    return context.dependOnInheritedWidgetOfExactType<WidgetTheme>()?.data;
  }

  @override
  bool updateShouldNotify(WidgetTheme oldWidget) {
    return data != oldWidget.data;
  }
}

class WidgetThemeData {
  final EmptyStyle emptyStyle;
  final CommonProgressIndicatorStyle progressIndicatorStyle;
  final CustomButtonStyle buttonStyle;
  final String imagePlaceholder;
  final Icon appbarBackIcon;
  final bool appBarCenterTitle;

  WidgetThemeData({
    this.emptyStyle = const EmptyStyle(),
    this.progressIndicatorStyle = const CommonProgressIndicatorStyle(),
    this.buttonStyle = const CustomButtonStyle(),
    this.imagePlaceholder = Images.placeholder,
    this.appbarBackIcon = const Icon(Icons.chevron_left),
    this.appBarCenterTitle = false,
  });
}
